//1.引入sdk
const qiniuUploader = require("./qiniu.js");
Page({
    data: {},

    onLoad: function (options) {
        let _this = this;
        // 通过后台api拿到token等配置信息
        let config = {
            uptoken:
                "vHg2e7nOh7Jsucv2Azr5FH6omPgX22zoJRWa0FN5:Fc_lk8AI0qvtDUjOqp3JQfefjYg=:eyJkZWxldGVBZnRlckRheXMiOjEsInJldHVybkJvZHkiOiJ7XCJrZXlcIjpcIiQoa2V5KVwiLFwiaGFzaFwiOlwiJChldGFnKVwiLFwiZnNpemVcIjokKGZzaXplKSxcImJ1Y2tldFwiOlwiJChidWNrZXQpXCIsXCJuYW1lXCI6XCIkKHg6bmFtZSlcIn0iLCJzY29wZSI6InNkay16MiIsImRlYWRsaW5lIjoxNTkxNDYwNjIwfQ==",
            region: "SCN",
            domain: "http://oonwiy2x0.bkt.clouddn.com",
            prefix: "path1/path2/", //可选参数：前缀 
        };

        // 调用初始化sdk
        qiniuUploader.init({
            region: config.region,
            domain: config.domain,
            uptoken: config.token,
            prefix: config.prefix,
        });
    },

    chooseimage() {
        //单图上传
        wx.chooseImage({
            count: 1,
            success(res) {
                qiniuUploader.upload({
                    filePath: res.tempFilePaths[0],
                    success(qiniures) {
                        //上传成功
                        console.log("qiniures:", qiniures);
                    },
                    fail(qiniures) {
                        //上传失败
                    },
                    progress(qiniures) {
                        console.log("上传进度:", qiniures.progress);
                    },
                });
            },
        });
    },
});
